/**
 * 文件名：****.java
 * 版权：Copyright Lightkit All Rights Reserved.
 * 描述：*****
 */
package com.lightkits.wms.domain.saveonhand;

import com.lightkits.framework.common.logging.Logger;
import com.lightkits.framework.common.logging.LoggerFactory;
import com.lightkits.framework.common.model.CheckResult;
import com.lightkits.framework.common.model.IResult;
import com.lightkits.framework.soa.hzero.executor.ServiceExecutor;
import com.lightkits.wms.domain.saveonhand.models.OnhandParams;
import com.lightkits.wms.domain.saveonhand.service.UseParamsDomain;
import com.lightkits.wms.dto.onhand.SaveOnhandRequestType;
import com.lightkits.wms.dto.onhand.SaveOnhandResponseType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * SaveOnhandExecutor
 *
 * @author jing.wei@hand-china.com
 * Created on 2019/2/20 16:39
 */
@Component
public class SaveOnhandExecutor implements
        ServiceExecutor<SaveOnhandRequestType, SaveOnhandResponseType> {
    private static final Logger LOGGER = LoggerFactory.getLogger(SaveOnhandExecutor.class);
    private final UseParamsDomain useParamsDomain;

    @Autowired
    public SaveOnhandExecutor(UseParamsDomain useParamsDomain) {
        this.useParamsDomain = useParamsDomain;
    }

    @Override
    public SaveOnhandResponseType service(SaveOnhandRequestType request) {
        SaveOnhandResponseType response = new SaveOnhandResponseType();
            CheckResult<String> checkResultRes = new CheckResult<>();
            checkResultRes.setSuccessful(true);
            CheckResult<OnhandParams> checkResult = useParamsDomain.getOnhandParams(request.getOnhandDTO());
            if (!checkResult.isSuccessful() || checkResult.getData() == null) {
                response.setSuccessful(false);
                response.setMessage(checkResultRes.getMessage());
                return response;
            }
            OnhandParams params = checkResult.getData();
            IResult result = useParamsDomain.insertValue(params);
            result.fill(response);
        return response;
    }
}
